<?php
/*****************************************************************
 * Fusion.Board
 *
 * @author                Denis Wrobel
 * @license               http://www.gnu.org/licenses/gpl-3.0.html
 * @version               0.1
 *
 *****************************************************************/

if( !defined( 'IN_SCRIPT' ) )
{
    die( 'Go Away!' );
}

class Mail
{
    private $object = NULL;
    
    public function create()
    {
        require_once( CLASSES . 'phpmailer.Class.php' );
        
        $this->object = new PHPMailer();
    }
    
    public function send_mail( $receiver, $subject, $message )
    {
        global $board, $smtp;
        
        if( !$this->object instanceof PHPMailer )
        {
            $this->create();
        }
        
        $this->object->IsSMTP();
        $this->object->Host       = $smtp['host']; // SMTP server
        $this->object->SMTPAuth   = true; // enable SMTP authentication
        $this->object->SMTPSecure = $smtp['prefix']; // sets the prefix to the servier
        $this->object->Host       = $smtp['host']; // sets GMAIL as the SMTP server
        $this->object->Port       = $smtp['port']; // set the SMTP port for the GMAIL server
        $this->object->Username   = $smtp['username'];
        $this->object->Password   = $smtp['password']; 
        
        $this->object->SetFrom( $smtp['username'] , $board['board_name']);
        
        $this->object->Subject = $subject . ' - ' . $board['board_name'];
        
        $this->object->AltBody = 'To view the message, please use an HTML compatible email viewer!';
        
        $this->object->MsgHTML( $message );
        
        $this->object->AddAddress( $receiver, '' );
        
        if( !$this->object->Send() )
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

?>